package com.ruoyi.basedocument.service.impl;

import java.util.HashMap;
import java.util.List;

import com.ruoyi.basedocument.domain.BomCostcenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basedocument.mapper.BomRawmaterialMapper;
import com.ruoyi.basedocument.domain.BomRawmaterial;
import com.ruoyi.basedocument.service.IBomRawmaterialService;

/**
 * BOM原材料Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-12
 */
@Service
public class BomRawmaterialServiceImpl implements IBomRawmaterialService 
{
    @Autowired
    private BomRawmaterialMapper bomRawmaterialMapper;

    /**
     * 查询BOM原材料
     * 
     * @param id BOM原材料主键
     * @return BOM原材料
     */
    @Override
    public BomRawmaterial selectBomRawmaterialById(String id)
    {
        return bomRawmaterialMapper.selectBomRawmaterialById(id);
    }

    /**
     * 查询BOM原材料列表
     * 
     * @param bomRawmaterial BOM原材料
     * @return BOM原材料
     */
    @Override
    public List<BomRawmaterial> selectBomRawmaterialList(BomRawmaterial bomRawmaterial)
    {
        return bomRawmaterialMapper.selectBomRawmaterialList(bomRawmaterial);
    }

    /**
     * 查询BOM原材料列表
     *
     * @param bomRawmaterial BOM原材料
     * @return BOM原材料
     */
    @Override
    public List<BomRawmaterial> selectBomRawmaterialList2(BomRawmaterial bomRawmaterial)
    {
        return bomRawmaterialMapper.selectBomRawmaterialList2(bomRawmaterial);
    }

    /**
     * 新增BOM原材料
     * 
     * @param bomRawmaterial BOM原材料
     * @return 结果
     */
    @Override
    public int insertBomRawmaterial(BomRawmaterial bomRawmaterial)
    {
        BomRawmaterial obj = new BomRawmaterial();
        obj.setMaterialnumber(bomRawmaterial.getMaterialnumber());
        obj.setStatus("1");
        List<BomRawmaterial> objs = bomRawmaterialMapper.selectBomRawmaterialList2(obj);
        if(objs!=null&&objs.size()!=0){
            throw new RuntimeException("已手工新增过相同编码的价格，请调整原价格:"+bomRawmaterial.getMaterialnumber());
        }
        return bomRawmaterialMapper.insertBomRawmaterial(bomRawmaterial);
    }

    /**
     * 修改BOM原材料
     * 
     * @param bomRawmaterial BOM原材料
     * @return 结果
     */
    @Override
    public int updateBomRawmaterial(BomRawmaterial bomRawmaterial)
    {
        return bomRawmaterialMapper.updateBomRawmaterial(bomRawmaterial);
    }

    /**
     * 批量删除BOM原材料
     * 
     * @param ids 需要删除的BOM原材料主键
     * @return 结果
     */
    @Override
    public int deleteBomRawmaterialByIds(String[] ids)
    {
        return bomRawmaterialMapper.deleteBomRawmaterialByIds(ids);
    }

    /**
     * 删除BOM原材料信息
     * 
     * @param id BOM原材料主键
     * @return 结果
     */
    @Override
    public int deleteBomRawmaterialById(String id)
    {
        return bomRawmaterialMapper.deleteBomRawmaterialById(id);
    }
    public HashMap introductionPrice(String[] numbers)
    {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < numbers.length; i++) {
            String number = numbers[i];
            if(i==numbers.length-1){
                stringBuilder.append("'"+number+"'");
                continue;
            }
            stringBuilder.append("'"+number+"',");
        }
        List<BomRawmaterial> bomRawmaterials = bomRawmaterialMapper.selectBomRawmaterialListTointroductionPrice(stringBuilder.toString());
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("data",bomRawmaterials);
        return objectObjectHashMap;
    }
}
